<div id="lesDroitsDyn">
<div>
  <strong>Aucun droits</strong>
  <ul id="listAucunDroits">
<!-- BEGIN utilisateurNone -->
    <li id="l0_{utilisateurNone.LOGIN}">{utilisateurNone.LOGIN}</li>
<!-- END utilisateurNone -->
  </ul>
</div>

<div>
  <strong>Lecture</strong>
  <ul id="listLecture">
<!-- BEGIN utilisateurLecture -->
    <li id="l1_{utilisateurLecture.LOGIN}">{utilisateurLecture.LOGIN}</li>
<!-- END utilisateurLecture -->
  </ul>
</div>

<div>
  <strong>Ecriture</strong>
  <ul id="listEcriture">
<!-- BEGIN utilisateurModification -->
    <li id="l2_{utilisateurModification.LOGIN}">{utilisateurModification.LOGIN}</li>
<!-- END utilisateurModification -->
  </ul>
</div>
<div style="clear: both; display: block; width: 655px; text-align: center;">
  <input type="button" id="sendDroits" value="Apply" />
</div>
</div>

<script type="text/javascript">
// <![CDATA[
  Sortable.create("listAucunDroits",
    {dropOnEmpty:true,containment:["listAucunDroits","listEcriture","listLecture"],constraint:false});
  Sortable.create("listLecture",
    {dropOnEmpty:true,containment:["listAucunDroits","listEcriture","listLecture"],constraint:false});
  Sortable.create("listEcriture",
    {dropOnEmpty:true,containment:["listAucunDroits","listEcriture","listLecture"],constraint:false});
  $('sendDroits').onclick = function()
{
var fin = new Array();
var fin_d = new Array();
cpt = 0;

	var pasDeDroit = Sortable.serialize('listAucunDroits',{name:'a'}).replace(/&a\[\]=/g,',').replace(/^a\[\]=/,'');
var n = pasDeDroit==''?0:pasDeDroit.split(',').length;
if(n>0)
{
var t = new Array();
for(var i=0; i<n; i++)
{
	t[i] = '0';
}
fin[cpt] = pasDeDroit;
fin_d[cpt++] = t.join(',');
}


var lecture = Sortable.serialize('listLecture',{name:'a'}).replace(/&a\[\]=/g,',').replace(/^a\[\]=/,'');
var n = lecture==''?0:lecture.split(',').length;
if(n>0)
{
var t = new Array();
for(var i=0; i<n; i++)
{
	t[i] = '1';
}
fin[cpt] = lecture;
fin_d[cpt++] = t.join(',');
}

var ecriture = Sortable.serialize('listEcriture',{name:'a'}).replace(/&a\[\]=/g,',').replace(/^a\[\]=/,'');
var n = ecriture==''?0:ecriture.split(',').length;
if(n>0)
{
var t = new Array();
for(var i=0; i<n; i++)
{
	t[i] = '2';
}
fin[cpt] = ecriture;
fin_d[cpt++] = t.join(',');
}

var poststring = 'ID_ITEM[]={ID_ITEM}&ACTION_ITEM=MOD_DROITS&LOGIN_DROITS_ITEM[]='+fin.join(',')+'&DROITS_ITEM[]='+fin_d.join(',');
//alert(poststring);

                    var okFunc = function(t)
                    {
                        var retour = t.responseText.split(':');
                        if(retour[0] == 'ok')
                        {
			alert('Droits changés avec succès');	
                        }
                        else
                        {
                            alert(retour[1]);
                        }
                    }
                    
                    debLoad();
                    new Ajax.Request('index.php?page=ajaxItem', 
                    {
                        parameters:poststring, 
                        onSuccess: okFunc, 
                        onFailure: errFunc, 
                        onComplete:finLoad
                    });

}
// ]]>
</script>
